package com.dq.Controller;

import com.dq.Pojo.Result;
import com.dq.Pojo.Student;
import com.dq.Pojo.Teacher;
import com.dq.Service.TeaService;
import com.github.pagehelper.PageInfo;
import org.apache.poi.ss.formula.functions.Intercept;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/tea")
public class TeaController {
    @Autowired
    private TeaService teaService;

    //教师信息添加
    @PostMapping("/addTea")
    public Result<Teacher> addStu(@RequestBody Teacher teacher){
        teaService.addtea(teacher);
        return Result.success(teacher);
    }

    //教师信息查询
    @GetMapping("/findtea")
    public Result<Teacher> findtea(@RequestParam Integer id){
        Teacher teacher=teaService.findtea(id);
        if (teacher == null){
            return Result.error("失败");
        }
        return Result.success(teacher);
    }
    //教师信息修改
    @PutMapping("/updateTea")
    public Result<Teacher> updateStu(@RequestBody Teacher teacher){
        teaService.update(teacher);
        return Result.success(teacher);
    }
    //获取教师信息
    @GetMapping("/findAll")
    public Result<PageInfo<Teacher>> findtea(@RequestParam Integer pageNum,
                                             @RequestParam Integer pageSize,
                                             @RequestParam String name,
                                             @RequestParam String teano){
        PageInfo<Teacher> pageInfo=teaService.findAll(pageNum,pageSize,name,teano);
        return Result.success(pageInfo);

    }
    @DeleteMapping("/teadel")
    public Result del(@RequestParam Integer id){
        teaService.delete(id);
        return  Result.success();

    }
    //教师所有信息
    @GetMapping("/find")
    public Result find(){
        List<Teacher> teacherList=teaService.find();
        return  Result.success(teacherList);
    }



}
